package com.swlz.service.impl;

import java.sql.SQLException;

import com.swlz.dao.RechargeDAO;
import com.swlz.entity.Recharge;
import com.swlz.exception.CodeException;
import com.swlz.service.RechargeService;
import com.swlz.vo.PageVO;

/**
 * <pre>
 * 业务逻辑接口具体实现类
 * 充值记录
 * ClassName : com.swlz.service.impl.RechargeServiceImpl
 * Author :swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-06-25 06:20:24
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
public class RechargeServiceImpl implements RechargeService {
	
	private RechargeDAO rechargeDAO = new RechargeDAO();

	@Override
	public int add(Recharge recharge) throws CodeException {
		try {
			return rechargeDAO.insertSelective(recharge);
		} catch (SQLException e) {
			throw new CodeException(500, "添加充值记录错误",e);
		}
	}

	@Override
	public int update(Recharge recharge) throws CodeException {
		try {
			return rechargeDAO.updateSelective(recharge);
		} catch (SQLException e) {
			throw new CodeException(501, "修改充值记录错误",e);
		}
	}

	@Override
	public int delete(Long rechargeId) throws CodeException {
		try {
			return rechargeDAO.deleteById(rechargeId);
		} catch (SQLException e) {
			throw new CodeException(502, "删除充值记录错误",e);
		}
	}

	@Override
	public Recharge get(Long rechargeId) throws CodeException {
		try {
			return rechargeDAO.selectById(rechargeId);
		} catch (SQLException e) {
			throw new CodeException(503, "获取充值记录失败",e);
		}
	}

	@Override
	public PageVO<Recharge> page(Recharge recharge, Integer current, Integer rowMax) throws CodeException {
		try {
			long total = rechargeDAO.countByModel(recharge);
			PageVO<Recharge> page = new PageVO<>(total, current, rowMax);
			return page.setList(rechargeDAO.selectByModel(recharge, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			throw new CodeException(504, "获取充值记录分页数据失败",e);
		}
	}


}
